package com.woniu.controller;

import com.woniu.service.BookService;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/book")
//可以通过前端vue.config.js配置解决
//@CrossOrigin(origins = "*")    //此类的所有接口允许跨域访问
public class BookController {
    @Autowired
    private BookService bookService;

    @RequestMapping("/queryAll")
    public ResData<?> queryAllBook(){
        return bookService.queryAll();
    }

    @RequestMapping("/querySecActiveAll")
    public ResData<?> querySecActiveAll(){
        return bookService.querySecActiveAll();
    }

    @GetMapping("/queryBookDetail")
    public ResData<?> queryBookDetailByBookId(Integer bookId){
        //断言校验参数合法性
        //参数一：校验的对象
        //参数二：校验不通过显示的内容
        Assert.notNull(bookId,"bookId is null");
        return bookService.queryBookDetailByBookId(bookId);

    }
}
